package cn.tedu._04mvc.controller;


import cn.tedu._04mvc.pojo.dto.BMIDto;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
public class BmiController {
    //http://localhost:8080/bmi?height=1.73&weight=80
    @PostMapping ("/bmi")
    @ResponseBody
    public String bmi(BMIDto bmiDto) {
        Double weight = bmiDto.getWeight();
        Double height = bmiDto.getHeight();
        Double d = weight / (height * height);
        if (d < 18.5) {
            return "BMI:" + d + ",兄弟，你好细啊";
        }  if (d < 24 & d > 18.5) {
            return "BMI:" + d + ",兄弟，身材不错啊";
        }  if (d < 27 & d > 24) {
            return "BMI:" + d + "，兄弟，脂包肌吗";
        }
           return "BMI:" + d + "，兄弟少吃点，改减肥啦";

    }


    /**
     * 路径参数传递
     * 请求路径：/bmi/{height}/{weight}
     * 请求参数：身高height,体重weight
     * 参数类型：路径参数
     *
     */
    @GetMapping("/bmi/{height}/{weight}")
    @ResponseBody
    public String bmi2(@PathVariable Double height,@PathVariable Double weight){
        Double d = weight / (height * height);
        if (d < 18.5) {
            return "BMI:" + d + ",兄弟，你好细啊";
        }  if (d < 24 & d > 18.5) {
            return "BMI:" + d + ",兄弟，身材不错啊";
        }  if (d < 27 & d > 24) {
            return "BMI:" + d + "，兄弟，脂包肌吗";
        }
        return "BMI:" + d + "，兄弟少吃点，改减肥啦";

    }









}
